package utils

import (
	"crypto/sha256"
	"encoding/hex"
)

/**
 * 计算字符串的SHA256哈希值
 */
func Sha256(text string) string {
	engine := sha256.New()
	engine.Write([]byte(text))
	hash := engine.Sum(nil)

	return hex.EncodeToString(hash)
}

func validatePasswd(plainPasswd, salt, passwd string) bool {
	return Sha256(plainPasswd+salt) == passwd
}

func ComputePasswd(plainPasswd, salt string) string {
	return Sha256(plainPasswd + salt)
}
